package ik.xcj.hostpital.manage.controller;

import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import ik.xcj.hostpital.manage.service.IHospitalSetService;
import ik.xcj.hostpital.manage.web.JsonResult;
import ik.xcj.hostpital.manage.pojo.dto.HospitalSetAddNewDTO;
import ik.xcj.hostpital.manage.pojo.dto.HospitalSetUpdateDTO;
import ik.xcj.hostpital.manage.pojo.vo.HospitalSetQVO;
import ik.xcj.hostpital.manage.pojo.vo.HospitalSetVO;
import ik.xcj.hostpital.manage.service.IHospitalSetService;
import ik.xcj.hostpital.manage.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/hospitalSet")
@Api(tags = "医院管理模块")
public class HospitalSetController {
    @Autowired
    IHospitalSetService iHospitalSetService;

    // http://localhost:9080/hospitalSet/add-new
    @ApiOperation("添加医院设置详情")
    @ApiOperationSupport(order = 110)
    @PostMapping("/add-new")
    public JsonResult<Void> insert(HospitalSetAddNewDTO hospitalSetAddNewDTO){
        iHospitalSetService.insert(hospitalSetAddNewDTO);
        return JsonResult.ok();
    }

    // http://localhost:9080/xxx/delete
    @ApiOperation("删除医院设置详情")
    @ApiOperationSupport(order = 210)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteById(@Range(min = 1, max = 1000000, message = "删除医院管理详情失败，医院管理ID非法！")
                                       @PathVariable Long id){
        iHospitalSetService.delete(id);
        return JsonResult.ok();
    }

    // http://localhost:9080/xxx/update
    @ApiOperation("修改医院设置详情")
    @ApiOperationSupport(order = 310)
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> update(@PathVariable Long id , HospitalSetUpdateDTO hospitalSetUpdateDTO){
        iHospitalSetService.updateById(id,hospitalSetUpdateDTO);
        return JsonResult.ok();
    }

    // http://localhost:9080/hospitalSet/xxxx
    @ApiOperation("根据id查询医院设置详情")
    @ApiOperationSupport(order = 410)
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<HospitalSetQVO> selectById(@Range(min = 1, max = 1000000, message = "查询医院管理详情失败，医院管理ID非法！")
                                                 @PathVariable Long id){
        HospitalSetQVO hospitalSetQVO = iHospitalSetService.selectById(id);
        return JsonResult.ok(hospitalSetQVO);
    }

    // http://localhost:9080/hospitalSet
    @ApiOperation("查询医院设置列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("/page")
    public JsonResult<PageInfo<HospitalSetQVO>> list(Integer page,Integer pageSize){
        PageInfo<HospitalSetQVO> list = iHospitalSetService.list(page, pageSize);
        return JsonResult.ok(list);
    }

}
